package com.woniuxy.cq.phrase3.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.cq.phrase3.common.DateUtil;
import com.woniuxy.cq.phrase3.common.Result;
import com.woniuxy.cq.phrase3.dao.ProjectMapper;
import com.woniuxy.cq.phrase3.entity.Leader;
import com.woniuxy.cq.phrase3.dao.LeaderMapper;
import com.woniuxy.cq.phrase3.entity.Project;
import com.woniuxy.cq.phrase3.service.ILeaderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.cq.phrase3.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2020-09-07
 */
@Service
public class LeaderServiceImpl extends ServiceImpl<LeaderMapper, Leader> implements ILeaderService {
    @Autowired
    private ProjectMapper projectMapper;

    @Autowired
    private UserService userService;
    /**
     * 主任批准项目
     *
     * @param productId
     */
    @Override
    public void directorAllow(Integer productId) {
        projectMapper.allowProjectByDirector(productId, new Date());

    }

    /**
     * 主任不批准项目
     *
     * @param productId
     */
    @Override
    public void directorFail(Integer productId) {
        projectMapper.failProjectByDirector(productId,new Date());

    }

    /**
     * 主任直接批准项目
     *
     * @param productId
     */
    @Override
    public void directorPass(Integer productId) {
       projectMapper.passProjectByDirector(productId,new Date());
    }

    @Override
    public IPage<Project> chairmanPageList(int pageIdx, int pageSize, String projectStatus,String  projectName) {

            Page<Project> page = new Page<>(pageIdx,pageSize);
        System.out.println(projectStatus+"====="+projectName);
            IPage<Project> teacherIPage =  projectMapper.chairmanPageList(page,projectStatus,projectName);
            return teacherIPage;

    }

    @Override
    public Result dispacheroperation(Integer leaderId, Integer projectId, String projectStatus) {
        String roles= userService.findRolesByUserId(leaderId);
        if (roles.equals("decision")){
            //局长
        }
        if (projectStatus.equals("1")){
            //直接批准
            chairmanPass(projectId);
        }else if (projectStatus.equals("2")){
            //不批准
            chairmanFail(projectId);
        }else{
            //批准通过
            chairmanAllow(projectId);
        }

        return null;
    }

    /**
     * 局长查询所有待处理的事项
     *
     * @param leaderId
     * @return
     */
    @Override
    public List<Project> leaderListByChairman(Integer leaderId) {
        List<Project> projects = projectMapper.leaderListByChairman(leaderId);

        return projects;
    }

    /**
     * 局长同意某项目
     * @param productId
     */
    @Override
    public void chairmanAllow(Integer productId) {
        projectMapper.allowProjectByChairman(productId,new Date());

    }

    /**
     * 局长直接批准项目
     *
     * @param productId
     */
    @Override
    public void chairmanPass(Integer productId) {
         projectMapper.passProjectByChairman(productId,new Date());
    }

    /**
     * 局长直接不批准项目
     *
     * @param productId
     */
    @Override
    public void chairmanFail(Integer productId) {
        projectMapper.failProjectByChairman(productId,new Date());
    }

    /**
     * 主任查询所需要处理的事项
     *
     * @param leaderId
     * @return
     */
    @Override
    public List<Project> leaderListByDirector(Integer leaderId) {
        List<Project> projects = projectMapper.leaderListByDirector(leaderId);

        return projects;
    }
}
